{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "815ad8e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from tkinter import*\n",
    "from tkinter.messagebox import*\n",
    "from tkinter.ttk import*\n",
    "ke={}\n",
    "\n",
    "xia={}\n",
    "\n",
    "wan={}\n",
    "def write():\n",
    "    with open('课程表 / morning.tx',encoding='UTF-8') as file:\n",
    "        for line in file:\n",
    "            line.rstrip('\\n')\n",
    "            zhou,xue=line.split(':')\n",
    "            ke[zhou]=xue\n",
    "    with open('课程表\\/afternoon.txt',encoding='UTF-8') as file:\n",
    "        for line in file:\n",
    "            line.rstrip('\\n')\n",
    "            zhou2,xue2=line.split(':')\n",
    "            xia[zhou2]=xue2\n",
    "    with open('课程表\\/night.txt',encoding='UTF-8') as file:\n",
    "        for line in file:\n",
    "            line.rstrip('\\n')\n",
    "            zhou3, xue3 = line.split(':')\n",
    "            wan[zhou3] = xue3\n",
    "\n",
    "\n",
    "def search():\n",
    "    try:\n",
    "        if cb.get()=='上午':\n",
    "            if cbb.get() in ke:\n",
    "                showinfo('提示','{}{}的课程表是；{}'.format(cbb.get(),cb.get(),ke[cbb.get()]))\n",
    "            else:\n",
    "                showinfo('提示','这一天上午无课程！')\n",
    "        if cb.get() == '下午':\n",
    "            if cbb.get() in xia:\n",
    "                        showinfo('提示', '{}{}的课程表是；{}'. format(cbb.get(), cb.get(), xia[cbb.get()]))\n",
    "            else:\n",
    "                        showinfo('提示', '这一天下午无课程！')\n",
    "\n",
    "        if cb.get()=='晚上':\n",
    "            if cbb.get() in wan:\n",
    "                showinfo('提示','{}{}的课程表是；{}'.format(cbb.get(),cb.get(),wan[cbb.get()]))\n",
    "            else:\n",
    "                showinfo('提示','这一天晚上无课程！')\n",
    "    except KeyError:\n",
    "            showwarning('提示','该时段无课程！')\n",
    "\n",
    "\n",
    "\n",
    "write();\n",
    "root=Tk()\n",
    "root.title('课表查询')\n",
    "root.geometry('330x50+300+300')\n",
    "var=StringVar(root)\n",
    "var.set('请选择时间')\n",
    "cb=Combobox(root,textvariable=var)\n",
    "cb['value']=('上午','下午','晚上')\n",
    "cb.grid(row=0,column=0)\n",
    "var1=StringVar(root)\n",
    "var1.set('请选择周几')\n",
    "cbb=Combobox(root,textvariable=var1)\n",
    "cbb['value']=('周一','周二','周三','周四','周五')\n",
    "cbb.grid(row=0,column=1)\n",
    "Button(root,text='确定',command=search).grid(row=1,column=0,columnspan=2)\n",
    "\n",
    "root.mainloop()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3ad294ed",
   "metadata": {},
   "source": [
    "#### 心得\n",
    "* python对符号和空格等要求严格，修改 符号和空格的时候的心理反应大概是：这也能报错？这也不报错？\n",
    "* 代码就像女盆友生气的时候，你对她说了一大堆话，她却无动于衷\n",
    "* 设置窗口大小的那里居然 是用x而不是用×，只能说是很有特色了\n",
    "* gitee怎么有些 奇怪的屏蔽词\n",
    "* 写的时候遇到了下列错误（节选，ps百度 真是个好东西）：LookupError: unknown encoding: uft-8  TypeError: format expected at most 2 arguments, got 3  ValueError: too many values to unpack (expected 2)  ValueError: too many values to unpack  SyntaxError: invalid syntax   IndentationError: unindent does not match any outer indentation level"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "698f0234",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
